package com.naizhuai.ui.msgmanager;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.naizhuai.R;
import com.naizhuai.ui.components.CircleImageView;
import com.naizhuai.ui.entity.User.AppMessage;
import com.naizhuai.ui.mianbusiness.action.ActionExamineActivity;
import com.naizhuai.ui.mianbusiness.setting.ThankCardPagerActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author：lichenxi
 * @date 2018/6/14 14
 * email：525603977@qq.com
 * Fighting
 */
public class MsgDataAdapter extends RecyclerView.Adapter<MsgDataAdapter.ViewHolder> {
    public static final String   STACK_MAIL="1";
    private static final String   THANK_PAGE="8";
    private static final String   EVALUATED="5";
    private static final String   PERSON_EXAMINE="6";
    private List<AppMessage> result;

    public void setResult(List<AppMessage> result) {
        this.result = result;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_msg_data_layout, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        //各种判断 点击进入对应的 界面
        AppMessage appMessage = result.get(position);
        Context context=holder.itemView.getContext();
        holder.title.setText(appMessage.messageTitle);
        holder.content.setText(appMessage.messageContent);
        if ("1".equals(appMessage.readPoint)){
            holder.tvDot.setVisibility(View.VISIBLE);
        }else {
            holder.tvDot.setVisibility(View.GONE);
        }

        if (THANK_PAGE.equals(appMessage.messageCategory)) {
          holder.circleImageView.setImageResource(R.drawable.icon_thank_page);
        }else if (EVALUATED.equals(appMessage.messageCategory)){
            holder.circleImageView.setImageResource(R.drawable.icon_evaluated);
        }else if (PERSON_EXAMINE.equals(appMessage.messageCategory)){
            holder.circleImageView.setImageResource(R.drawable.icon_person_examine);
        }else if (STACK_MAIL.equals(appMessage.messageCategory)){
            holder.circleImageView.setImageResource(R.drawable.icon_stack_mail);
        }else {
            holder.circleImageView.setImageResource(R.drawable.icon_main_flow);
        }

        holder.itemView.setOnClickListener(v -> {
            if (THANK_PAGE.equals(appMessage.messageCategory)) {
                //感谢卡
                ThankCardPagerActivity.startActivity(context);
                return;
            }
            if (PERSON_EXAMINE.equals(appMessage.messageCategory)) {
                //人员审核
                PersonExamineActivity.start(context);
                return;
            }
            MsgNotifyActivity.start(context,appMessage.messageCategory);
            holder.tvDot.setVisibility(View.GONE);
        });
    }

    @Override
    public int getItemCount() {
        return result != null ? result.size() : 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.circleImageView)
        CircleImageView circleImageView;
        @BindView(R.id.title)
        TextView title;
        @BindView(R.id.content)
        TextView content;
        @BindView(R.id.tv_dot)
        TextView tvDot;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }
    }

}
